package cn.stylefeng.guns.modular.system.service.ActivityEvent;

import cn.stylefeng.guns.modular.system.entity.BothSaleCommit;
import cn.stylefeng.guns.modular.system.service.BothSaleCommitService;
import cn.stylefeng.guns.sys.core.util.utility.StatusCode;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

public class BothSaleCommitEvent implements ExecutionListener {
    private BothSaleCommitService bothSaleCommitService = SpringContextHolder.getBean(BothSaleCommitService.class);

    @Override
    public void notify(DelegateExecution delegateExecution) {

        String eventName = delegateExecution.getEventName();
        BothSaleCommit bothSaleCommit = bothSaleCommitService.getOne(new QueryWrapper<BothSaleCommit>()
                .lambda().eq(BothSaleCommit::getProcessInstanceId,delegateExecution.getProcessInstanceId()));
        if ("end".equals(eventName)){
            bothSaleCommit.setCheckCode(StatusCode.FAIL.getVal());
        } else if ("start".equals(eventName)){
            bothSaleCommit.setCheckCode(StatusCode.SUCCESS.getVal());
        }
        bothSaleCommitService.getBaseMapper().updateById(bothSaleCommit);
    }
}
